package com.icez.calendar_view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.RoundedCornerTreatment
import com.google.android.material.shape.ShapeAppearanceModel

class CalendarTextView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : androidx.appcompat.widget.AppCompatTextView(context, attrs) {

    private val mPaint = Paint(Paint.ANTI_ALIAS_FLAG)

    private var mPointColor:Int = 0

    private var mPointSize:Float = 0f

    init {
        mPaint.style = Paint.Style.FILL
    }

    override fun onDraw(canvas: Canvas?) {
        if(mPointColor != 0){
            mPaint.color = mPointColor
            canvas?.drawCircle(width/2f,height.toFloat()-mPointSize - mPointSize/2,mPointSize,mPaint)
        }
        super.onDraw(canvas)
    }

    /**
     * 设置点的颜色
     * @sample
     * @author Icez
     */
    fun setPointColor(mPointColor:Int,mPointSize:Float){
        this.mPointColor = mPointColor
        this.mPointSize = mPointSize
        invalidate()
    }

    /**
     * 设置矩形
     * @sample
     * @author Icez
     */
    fun setRoundRect(mTopLeftRadius:Float = 0f,mTopRightRadius:Float = 0f,mBottomLeftRadius:Float = 0f,mBottomRightRadius:Float = 0f,bgColor:Int = Color.GRAY){
        val shapeModel = ShapeAppearanceModel.builder()
            .setAllCorners(RoundedCornerTreatment())
            .setTopLeftCornerSize(mTopLeftRadius)
            .setTopRightCornerSize(mTopRightRadius)
            .setBottomLeftCornerSize(mBottomLeftRadius)
            .setBottomRightCornerSize(mBottomRightRadius)
            .build()


        val backgroundDrawable = MaterialShapeDrawable(shapeModel).apply {
            paintStyle = Paint.Style.FILL_AND_STROKE
            setTint(bgColor)
        }


        background = backgroundDrawable
    }


}